<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
	ul{
		margin-left:25;padding:0;
 		list-style:none; 
	}
	.mini-checkboxlist-item{
		padding: 10px;
	}
</style>
</head>
<body>
	<div id="datagrid1" class="mini-datagrid" showPager="false" onlyCheckSelection="true" idField="id" allowCellWrap="true" url="customer_remind_find.do" style="width:100%;height:auto;">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div field="other" width="40" headerAlign="center" renderer="onActionRenderer" align="center">相关操作</div>
			<div field="cycleVal" width="50" headerAlign="center" align="center">周期</div>
			<div field="reminderTime" width="70" headerAlign="center" align="center" dateFormat="yyyy-MM-dd HH:mm:ss">时间</div>
			<div field="operatorUser" width="50" headerAlign="center" align="center">提醒对象</div>
			<div field="content" width="250" headerAlign="center" align="left">内容</div>
		</div>
	</div>
	<fieldset style="border:solid 1px #aaa;padding:3px;">
		<legend >添加客户提醒</legend>
		<input id="customer_id" class="mini-hidden" />
        <table cellspacing="10" cellpadding="0">
	        <tr>
	            <td>
	         	   	周期：
	            	<input id="cycle" name="cycle" style="width: 100px;" class="mini-combobox" valueField="keyName" textField="keyValue"
	                 	url="dictionary_cm_key_val_view.do?typeName=CUSTOMER_REMIND_TYPE" value="40" onvaluechanged="valuechanged"/>
	            </td>
	            <td>
	            	时间：
	            	<span id="each_day">
	            		<input id="each_day_1" class="mini-timespinner" required="true" format="HH:mm" />
	            	</span>
	            	<span id="each_week" style="display: none;">
	            		<input id="each_week_1" class="mini-combobox" style="width:100px;" textField="text" valueField="id" allowInput="false" required="true"
    						data="[{id:'1',text:'星期一'},{id:'2',text:'星期二'},{id:'3',text:'星期三'},{id:'4',text:'星期四'},{id:'5',text:'星期五'},{id:'6',text:'星期六'},{id:'0',text:'星期日'}]"/>
	            		<input id="each_week_2" class="mini-timespinner" required="true" format="HH:mm" />
	            	</span>
	            	<span id="each_month" style="display: none;">
	            		<input id="each_month_1" class="mini-spinner" minValue="1" maxValue="31" required="true"/>日--
	            		<input id="each_month_2" class="mini-timespinner"  format="HH:mm" required="true"/>
	            	</span>
	            	<span id="each_year" style="display: none;">
	            		<input id="each_year_1" class="mini-spinner" minValue="1" maxValue="12" required="true" style="width: 70px;"/>月--
	            		<input id="each_year_2" class="mini-spinner" minValue="1" maxValue="31" required="true" style="width: 70px;"/>日
	            		<input id="each_year_3" class="mini-timespinner" required="true" format="HH:mm" />
	            	</span>
	            	<span id="once" style="display: none;">
	            		<input id="once_1" class="mini-datepicker" allowInput="false" ondrawdate="onDrawDate" required="true"/>
	            		<input id="once_2" class="mini-timespinner" required="true" format="HH:mm" />
	            	</span>
	            </td>
	            <td>&nbsp;</td>
	        </tr>
	        <tr>
	        	<td colspan="2">
	        		内容：
	        		<input id="remind_content" class="mini-textbox" name="content" style="width: 750px;" required="true"/>
	        	</td>
	        	<td>
	        		<sec:authorize url='/customer_remind_save.do'>
	        		<a class="mini-button" onclick="onOk">添加</a>
	        		</sec:authorize>
	        	</td>
	        </tr>
    	</table>
	</fieldset>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	var cId = mini.get("customer_id");
	function SetData(data) {
		data = mini.clone(data);
		cId.setValue(data.customerId);
		grid.load({customerId: data.customerId});
	}
	
	function valuechanged(e) {
		if(e.value == 40) {						// 每天
			$("#each_day").show();
			$("#each_week").hide();
			$("#each_month").hide();
			$("#each_year").hide();
			$("#once").hide();
		} else if(e.value == 41) {				// 每月
			$("#each_day").hide();
			$("#each_week").hide();
			$("#each_month").show();
			$("#each_year").hide();
			$("#once").hide();
		} else if(e.value == 42) {				// 每年
			$("#each_day").hide();
			$("#each_week").hide();
			$("#each_month").hide();
			$("#each_year").show();
			$("#once").hide();
		} else if(e.value == 43) {				// 一次性
			$("#each_day").hide();
			$("#each_week").hide();
			$("#each_month").hide();
			$("#each_year").hide();
			$("#once").show();
		} else if(e.value == 44) {				// 每周
			$("#each_day").hide();
			$("#each_week").show();
			$("#each_month").hide();
			$("#each_year").hide();
			$("#once").hide();
		}
	}
	
	function onOk(){
		var cId = mini.get("customer_id");
		var remind_content = mini.get("remind_content").getFormValue();
		var cycle = mini.get("cycle").getValue();
		if(cycle == 40) {						// 每天
			var m1 = mini.get("each_day_1");
			if(remind_content){
				var v1 = m1.getFormValue();
				$.post("customer_remind_save.do",{cycle:cycle,reminderTime:v1,customerId:cId.getValue(),content:remind_content},function(data){
					if(data.success) {
						mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "添加成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
						grid.load({customerId: cId.getValue()});
						mini.get("remind_content").setValue("");
					}
				},"json");
			}
			
		} else if(cycle == 41) {				// 每月
			var m1 = mini.get("each_month_1").getFormValue();
			var m2 = mini.get("each_month_2").getFormValue();
			if(remind_content){
				$.post("customer_remind_save.do",{cycle:cycle,reminderTime:m1+"|"+m2,customerId:cId.getValue(),content:remind_content},function(data){
					if(data.success) {
						mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "添加成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
						grid.load({customerId: cId.getValue()});
						mini.get("remind_content").setValue("");
					}
				},"json");
			}
		} else if(cycle == 42) {				// 每年
			var m1 = mini.get("each_year_1").getFormValue();
			var m2 = mini.get("each_year_2").getFormValue();
			var m3 = mini.get("each_year_3").getFormValue();
			if(remind_content){
				$.post("customer_remind_save.do",{cycle:cycle,reminderTime:m1+"|"+m2+"|"+m3,customerId:cId.getValue(),content:remind_content},function(data){
					if(data.success) {
						mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "添加成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
						grid.load({customerId: cId.getValue()});
						mini.get("remind_content").setValue("");
					}
				},"json");
			}
		} else if(cycle == 43) {				// 一次性
			var m1 = mini.get("once_1").getFormValue();
			var m2 = mini.get("once_2").getFormValue();
			if(remind_content){
				$.post("customer_remind_save.do",{cycle:cycle,reminderTime:m1+"|"+m2,customerId:cId.getValue(),content:remind_content},function(data){
					if(data.success) {
						mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "添加成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
						grid.load({customerId: cId.getValue()});
						mini.get("remind_content").setValue("");
					}
				},"json");
			}
		} else if(cycle == 44) {				// 每周
			var m1 = mini.get("each_week_1").getFormValue();
			var m2 = mini.get("each_week_2").getFormValue();
			if(remind_content){
				$.post("customer_remind_save.do",{cycle:cycle,reminderTime:m1+"|"+m2,customerId:cId.getValue(),content:remind_content},function(data){
					if(data.success) {
						mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "添加成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
						grid.load({customerId: cId.getValue()});
						mini.get("remind_content").setValue("");
					}
				},"json");
			}
		}
	}
	
	function getYestoday(date){      
	    var yesterday_milliseconds=date.getTime()-1000*60*60*24;       
	    var yesterday = new Date();       
	        yesterday.setTime(yesterday_milliseconds);       
	    return yesterday;  
	}
	
	function onDrawDate(e) {
        var date = e.date;
        var d = new Date();
        var temp = getYestoday(d);

        if (date.getTime() < temp.getTime()) {
            e.allowSelect = false;
        }
    }

	function onActionRenderer(e) {
		return "<a href='javascript: deleteRemind(&#39;"+e.row.id+"&#39;);'>删除</a>";
	}
	
	function deleteRemind(rid) {
		mini.confirm("确定删除选中记录？", "删除",function (action) {
			if (action == "ok") {
				$.post("remind_delete.do",{id:rid},function(data){
					if(data.success) {
						mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "添加成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
						grid.load({customerId: cId.getValue()});
					}
				},"json");
			}
		});
	}
	
</script>
</body>
</html>
